﻿using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Drawing;
using System;
using ZgOffice.SvrMangr.Properties;


namespace ZgOffice.SvrMangr
{
    public partial class SvrMangr : XtraForm
    {
        private Icon m_frmerr;
        private Icon m_frmrun;
        private bool serviceStatus;
        private bool isClosedForm;
        public SvrMangr()
        {
            InitializeComponent();
            StatusUserControl suc = new StatusUserControl();
            suc.Dock = DockStyle.Fill;
            splitContainerControl.Panel2.Controls.Add(suc);
            try
            {
                m_frmerr = (System.Drawing.Icon)(Resources.ResourceManager.GetObject("frmerr"));//导入图标文件  
                m_frmrun = (System.Drawing.Icon)(Resources.ResourceManager.GetObject("frmrun"));
            }
            catch (Exception e)
            {
                MessageBox.Show("Error  " + e.Message, "Animate  Tray  -  Error");
            }  
        }

        private void setItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            splitContainerControl.Panel2.Controls.Clear();
            SetUserControl suc = new SetUserControl();
            suc.Dock = DockStyle.Fill;
            splitContainerControl.Panel2.Controls.Add(suc);
        }

        private void statusItem_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            splitContainerControl.Panel2.Controls.Clear();
            StatusUserControl suc = new StatusUserControl();
            suc.Dock = DockStyle.Fill;
            splitContainerControl.Panel2.Controls.Add(suc);
        }

        private void SvrMangr_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                if (isClosedForm == false)
                {
                    if (serviceStatus == true)
                    {
                        m_trayIcon.Icon = m_frmrun;
                    }
                    else
                    {
                        m_trayIcon.Icon = m_frmerr;
                    }
                    e.Cancel = true;
                    this.ShowInTaskbar = true;
                    this.Visible = false;
                }
            }
        }

        private void ExitMenu_Click(object sender, EventArgs e)
        {
            isClosedForm = true;
            m_trayIcon.Visible = false;
            m_trayIcon.Dispose();
            this.Close();
        }
    }
}